﻿using System;
using System.ComponentModel;
using CardGamesLibrary.Cards;

namespace CardGamesLibrary.Tables
{
    public class TableSeat : INotifyPropertyChanged
    {
        public ICardSet<FrenchDeckCard> Hand { get; set; }
        private Player _player;
        public TableSeat() : this(null)
        {
            
        }

        public TableSeat(Player player)
        {
            Player = player;
            Hand = new Hand<FrenchDeckCard>();
            Hand.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(Hand_PropertyChanged);
        }

        public Player Player { 
            get { return _player; } 
            set {
                _player = value;

                if (_player == null && Hand != null)
                { 
                    Hand.Clear();
                    NotifyPropertyChanged("Player");
                }
            } 
        }

        public event PropertyChangedEventHandler PropertyChanged;

        public void NotifyPropertyChanged(PropertyChangedEventArgs e)
        {
            var handler = PropertyChanged;

            if (handler != null)
                handler(this, e);
        }
        public void NotifyPropertyChanged(string propertyName)
        {
            NotifyPropertyChanged(new PropertyChangedEventArgs(propertyName));
        }


        void Hand_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            NotifyPropertyChanged("Hand");
        }
    }

   
}
